function open() {
  chrome.tabs.create({"url":"http://weibo.com", "selected":true});
}

function checkFirstTime() {
  if (localStorage["_sinna_weibo_shorcut_firstTime"] == undefined) {
    localStorage["_sinna_weibo_shorcut_firstTime"] = ":]";
    openOptions(true);
    return true;
  }
  return false;
}

function openOptions(firstTime) {
  var url = "options.html";

  var fullUrl = chrome.extension.getURL(url);
  chrome.tabs.getAllInWindow(null, function(tabs) {
    for (var i in tabs) { // check if Options page is open already
      var tab = tabs[i];
      if (tab.url == fullUrl) {
        chrome.tabs.update(tab.id, { selected: true }); // select the tab
        return;
      }
    }
    chrome.tabs.getSelected(null, function(tab) { // open a new tab next to currently selected tab
      chrome.tabs.create({
        url: url,
        index: tab.index + 1
      });
    });
  });
}

chrome.browserAction.onClicked.addListener(open);

checkFirstTime();
